Move non-transactional and non-idempotent code out of
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 26 Sep 2005 18:13:57 +0000 (19:13 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Mon, 26 Sep 2005 18:13:57 +0000 (19:13 +0100)
xenstore transaction retry loops in our device drivers.
Otherwise things get very smelly if a transaction fails and
is retried.

Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c

index ba64721bd6e7edfaa6d583e18f806b6e0d8aa100..c68e7f545acacfd591e28faebc00a263fb0aa04c 100644 (file)
@@ -80,6 +80,15 @@ static void frontend_changed(struct xenbus_watch *watch, const char *node)
                return;
        }
 
+       /* Map the shared frame, irq etc. */
+       err = blkif_map(be->blkif, ring_ref, evtchn);
+       if (err) {
+               xenbus_dev_error(be->dev, err, "mapping ring-ref %lu port %u",
+                                ring_ref, evtchn);
+               return;
+       }
+       /* XXX From here on should 'blkif_unmap' on error. */
+
 again:
        /* Supply the information about the device the frontend needs */
        err = xenbus_transaction_start();
@@ -112,14 +121,6 @@ again:
                goto abort;
        }
 
-       /* Map the shared frame, irq etc. */
-       err = blkif_map(be->blkif, ring_ref, evtchn);
-       if (err) {
-               xenbus_dev_error(be->dev, err, "mapping ring-ref %lu port %u",
-                                ring_ref, evtchn);
-               goto abort;
-       }
-
        err = xenbus_transaction_end(0);
        if (err == -EAGAIN)
                goto again;
index 598fecc3d10d9523f173d4f627d1a552f252a0b6..9d5b44d26cfb95ed05a1da40b5d0a27ca19f2c40 100644 (file)
@@ -591,17 +591,6 @@ again:
                goto abort_transaction;
        }
 
-       info->backend = backend;
-       backend = NULL;
-
-       info->watch.node = info->backend;
-       info->watch.callback = watch_for_status;
-       err = register_xenbus_watch(&info->watch);
-       if (err) {
-               message = "registering watch on backend";
-               goto abort_transaction;
-       }
-
        err = xenbus_transaction_end(0);
        if (err) {
                if (err == -EAGAIN)
@@ -610,10 +599,17 @@ again:
                goto destroy_blkring;
        }
 
- out:
-       if (backend)
-               kfree(backend);
-       return err;
+       info->watch.node = backend;
+       info->watch.callback = watch_for_status;
+       err = register_xenbus_watch(&info->watch);
+       if (err) {
+               message = "registering watch on backend";
+               goto destroy_blkring;
+       }
+
+       info->backend = backend;
+
+       return 0;
 
  abort_transaction:
        xenbus_transaction_end(1);
@@ -621,7 +617,10 @@ again:
        xenbus_dev_error(dev, err, "%s", message);
  destroy_blkring:
        blkif_free(info);
-       goto out;
+ out:
+       if (backend)
+               kfree(backend);
+       return err;
 }
 
 /* Setup supplies the backend dir, virtual device.
index b7273a5c518349175b9748209c18795b6734ff7d..9ddcd15f419a057acf23d111a87f128de2898f4a 100644 (file)
@@ -1148,17 +1148,6 @@ again:
                goto abort_transaction;
        }
 
-       info->backend = backend;
-       backend = NULL;
-
-       info->watch.node = info->backend;
-       info->watch.callback = watch_for_status;
-       err = register_xenbus_watch(&info->watch);
-       if (err) {
-               message = "registering watch on backend";
-               goto abort_transaction;
-       }
-
        err = xenbus_transaction_end(0);
        if (err) {
                if (err == -EAGAIN)
@@ -1167,12 +1156,19 @@ again:
                goto destroy_ring;
        }
 
+       info->watch.node = backend;
+       info->watch.callback = watch_for_status;
+       err = register_xenbus_watch(&info->watch);
+       if (err) {
+               message = "registering watch on backend";
+               goto destroy_ring;
+       }
+
+       info->backend = backend;
+
        netif_state = NETIF_STATE_CONNECTED;
 
- out:
-       if (backend)
-               kfree(backend);
-       return err;
+       return 0;
 
  abort_transaction:
        xenbus_transaction_end(1);
@@ -1180,7 +1176,10 @@ again:
        xenbus_dev_error(dev, err, "%s", message);
  destroy_ring:
        shutdown_device(info);
-       goto out;
+ out:
+       if (backend)
+               kfree(backend);
+       return err;
 }
 
 /* Setup supplies the backend dir, virtual device.
index c9c417cabde2d8e01dba99007a9eb0c7f86f4f46..48d56745f5afa448968fdba234a0b5ed70db342e 100644 (file)
@@ -88,31 +88,12 @@ static void frontend_changed(struct xenbus_watch *watch, const char *node)
                return;
        }
 
-
-       /*
-        * Tell the front-end that we are ready to go -
-        * unless something bad happens
-        */
-again:
-       err = xenbus_transaction_start();
-       if (err) {
-               xenbus_dev_error(be->dev, err, "starting transaction");
-               return;
-       }
-
-       err = xenbus_printf(be->dev->nodename,
-                           "ready", "%lu", ready);
-       if (err) {
-               xenbus_dev_error(be->dev, err, "writing 'ready'");
-               goto abort;
-       }
-
        err = tpmif_map(be->tpmif, ringref, evtchn);
        if (err) {
                xenbus_dev_error(be->dev, err,
                                 "mapping shared-frame %lu port %u",
                                 ringref, evtchn);
-               goto abort;
+               return;
        }
 
        err = tpmif_vtpm_open(be->tpmif,
@@ -125,6 +106,24 @@ again:
                 * Should close down this device and notify FE
                 * about closure.
                 */
+               return;
+       }
+
+       /*
+        * Tell the front-end that we are ready to go -
+        * unless something bad happens
+        */
+again:
+       err = xenbus_transaction_start();
+       if (err) {
+               xenbus_dev_error(be->dev, err, "starting transaction");
+               return;
+       }
+
+       err = xenbus_printf(be->dev->nodename,
+                           "ready", "%lu", ready);
+       if (err) {
+               xenbus_dev_error(be->dev, err, "writing 'ready'");
                goto abort;
        }
 
index 43ae40bdce2310d20a64b2ddf63ddd112d6747c0..0bd6114f436e6f48b9cb1d8825180e8b398d9f1b 100644 (file)
@@ -352,17 +352,6 @@ again:
                goto abort_transaction;
        }
 
-       info->backend = backend;
-       backend = NULL;
-
-       info->watch.node = info->backend;
-       info->watch.callback = watch_for_status;
-       err = register_xenbus_watch(&info->watch);
-       if (err) {
-               message = "registering watch on backend";
-               goto abort_transaction;
-       }
-
        err = xenbus_transaction_end(0);
        if (err == -EAGAIN)
                goto again;
@@ -371,10 +360,17 @@ again:
                goto destroy_tpmring;
        }
 
-out:
-       if (backend)
-               kfree(backend);
-       return err;
+       info->watch.node = backend;
+       info->watch.callback = watch_for_status;
+       err = register_xenbus_watch(&info->watch);
+       if (err) {
+               message = "registering watch on backend";
+               goto destroy_tpmring;
+       }
+
+       info->backend = backend;
+
+       return 0;
 
 abort_transaction:
        xenbus_transaction_end(1);
@@ -382,7 +378,10 @@ abort_transaction:
        xenbus_dev_error(dev, err, "%s", message);
 destroy_tpmring:
        destroy_tpmring(info, &my_private);
-       goto out;
+out:
+       if (backend)
+               kfree(backend);
+       return err;
 }